Skip to content

fix: resolve all eslint errors in utility and test files (#725)#725

Open
bnyashwanth wants to merge 5 commits intoaccordproject:mainfrom
bnyashwanth:main
Open

fix: resolve all eslint errors in utility and test files (#725)#725
bnyashwanth wants to merge 5 commits intoaccordproject:mainfrom
bnyashwanth:main

Conversation

@bnyashwanth
Copy link

This PR resolves the ESLint errors reported in issue #722, specifically focusing on @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument, and @typescript-eslint/unbound-method.

Changes made:

  • src/utils/helpers/errorUtils.ts: Replaced any types with NestedError and CommonErrorStructure interfaces to ensure type-safe JSON parsing.
  • src/utils/testing/setup.ts: Added MockCanvasContext interface, resolved empty mock function warnings, and correctly scoped the native getContext method to resolve unbound context errors.
  • src/tests/components/SettingsModal.test.tsx: Typed the mocked store state to eliminate unsafe return/call errors.

Closes #722

@bnyashwanth bnyashwanth requested a review from a team as a code owner February 21, 2026 14:30
@netlify
Copy link

netlify bot commented Feb 21, 2026

Deploy Preview for ap-template-playground ready!

Name Link
🔨 Latest commit ea6b867
🔍 Latest deploy log https://app.netlify.com/projects/ap-template-playground/deploys/69aeeeeac2d29d00086909d3
😎 Deploy Preview https://deploy-preview-725--ap-template-playground.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses ESLint rule violations in utilities and tests (notably no-explicit-any, no-unsafe-*, and unbound-method) by tightening types and adjusting mocks/exports to satisfy lint constraints.

Changes:

  • Introduces stronger typing for error-message extraction and test store mocks.
  • Refactors test environment setup mocks (matchMedia/canvas) to reduce lint violations.
  • Disables react-refresh/only-export-components for the Markdown editor context module to silence Fast Refresh linting.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/utils/testing/setup.ts Updates jsdom mocks for matchMedia and HTMLCanvasElement.getContext to address lint errors.
src/utils/helpers/errorUtils.ts Replaces any parsing with typed interfaces for safer JSON error extraction.
src/tests/components/SettingsModal.test.tsx Adds a typed StoreState for the zustand selector mock to avoid unsafe usage linting.
src/contexts/MarkdownEditorContext.tsx Adds an eslint disable for react-refresh/only-export-components.

Comment on lines +5 to +13
interface StoreState {
isSettingsOpen: boolean;
setSettingsOpen: () => void;
showLineNumbers: boolean;
setShowLineNumbers: () => void;
textColor: string;
backgroundColor: string;
toggleDarkMode: () => void;
}
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The StoreState type used for the mocked store doesn't match the real store API: setSettingsOpen and setShowLineNumbers are declared as () => void, but the actual store signatures accept a boolean argument. Updating these to (value: boolean) => void will keep the mock aligned with production types and prevents the test from silently accepting incorrect selector usage.

Copilot uses AI. Check for mistakes.
Comment on lines 1 to 2
/* eslint-disable react-refresh/only-export-components */
import { createContext, useContext, useState, ReactNode } from "react";
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling react-refresh/only-export-components for the entire file is quite broad and can hide future violations. Prefer scoping the suppression to the specific non-component export(s) (e.g., a single eslint-disable-next-line on the hook/type export), or move the exported types/hooks into a separate module so the context/provider module only exports components.

Copilot uses AI. Check for mistakes.
Comment on lines +65 to +70
// capture original method so we can delegate for non-2d calls
// use a loose any type to avoid lib.dom union conflicts
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const originalGetContext: any = HTMLCanvasElement.prototype.getContext.bind(
HTMLCanvasElement.prototype
);
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

originalGetContext is bound to HTMLCanvasElement.prototype, so later calling originalGetContext.call(this, ...) cannot rebind this. This means delegating to the original implementation for non-"2d" context IDs will run with the wrong this (the prototype), which can break callers expecting the native behavior. Preserve the original unbound method and invoke it with .call(this, ...) (or wrap it in a helper with an explicit this: HTMLCanvasElement type) so delegation uses the actual canvas instance; this also lets you avoid the any + broad no-unsafe-* disables.

Copilot uses AI. Check for mistakes.
Copy link
Member

@mttrbrts mttrbrts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review @copilot code review[agent] comments and add DCO sign-off. Thanks.

Signed-off-by: bnyashwanth <bnyashwanth2006@gmail.com>
@bnyashwanth bnyashwanth changed the title fix: resolve all eslint errors in utility and test files (#722) fix: resolve all eslint errors in utility and test files (#725) Mar 3, 2026
I, bnyashwanth <bnyashwanth2006@gmail.com>, hereby add my Signed-off-by to this commit: 84fb586

Signed-off-by: bnyashwanth <bnyashwanth2006@gmail.com>
Copilot AI review requested due to automatic review settings March 9, 2026 16:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.

toggleDarkMode: () => void;
}

// Update the mock
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment on line 15 reads // Update the mock, which is a process-oriented note (describing an action taken during development) rather than explanatory documentation. It doesn't convey why the mock is structured this way. The original comment // Mock the store - use inline functions to avoid hoisting issues was more informative. This should be updated to describe the intent of the mock.

Suggested change
// Update the mock
// Mock the Zustand store selector with a fixed settings state so SettingsModal can be tested in isolation

Copilot uses AI. Check for mistakes.
}

// for other context types, delegate to original
// for other context types, delegate to original
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a duplicate comment on two consecutive lines in the getContext mock implementation. Line 109 reads // for other context types, delegate to original and line 110 is an exact duplicate of the same comment. One of them should be removed.

Suggested change
// for other context types, delegate to original

Copilot uses AI. Check for mistakes.
Comment on lines +39 to +40
} else if (typeof parsed.error === 'string') {

Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the first if (parsed.error) block (lines 39–41), a new else if (typeof parsed.error === 'string') branch was added but its body is completely empty. The actual string-error handling then happens again immediately below in a separate if (typeof parsed.error === 'string') check (line 43). This empty else if block is dead/unreachable code and adds confusion. It should be removed entirely, keeping only the single if (typeof parsed.error === 'string') check that actually returns the value.

Suggested change
} else if (typeof parsed.error === 'string') {

Copilot uses AI. Check for mistakes.
canvas: HTMLCanvasElement;
}

// capture original method so we can delegate for non-2d calls
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments explaining the purpose of important code blocks (e.g., "Mock getComputedStyle for Ant Design components...", "Mock HTMLCanvasElement.getContext for lottie-web library...", "Return a mock CSSStyleDeclaration with string properties for .match() calls") were removed from setup.ts. These comments were valuable documentation explaining why the mocks are needed and what specific libraries/behaviors they address. Similarly, explanatory comments describing the various error structures handled in errorUtils.ts (e.g., "Handle Google error structure: ...", "Handle Mistral error structure: ...") were removed. These comments made the code self-documenting and easier to maintain.

Copilot uses AI. Check for mistakes.
);
};
// eslint-disable-next-line react-refresh/only-export-components

Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The eslint-disable-next-line react-refresh/only-export-components comment has been placed after the closing brace of MarkdownEditorProvider (line 35), but it is followed by a blank line before the function it is intended to suppress (useMarkdownEditorContext at line 37). ESLint disable-next-line comments apply to the immediately following non-blank line, so the blank line between the comment and the function means the directive may not work as intended and could suppress a warning on the wrong line. The comment should be placed directly above useMarkdownEditorContext with no blank line in between.

Suggested change

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: fixing the linting error npm run lint fails with 70 errors

3 participants